package club.cearnach.entity;

import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.Date;

/**
 * 人物表
 *
 * @author 阮胜
 * @date: 2018/5/10 10:12
 */
@Data
@Entity
@DynamicUpdate
@DynamicInsert
public class Person implements Serializable {
    private static final long serialVersionUID = 4398240606009652329L;
    @Id
    @Column(name = "person_id")
    @GeneratedValue
    private Integer id;

    @NotBlank
    @Column(name = "person_name")
    private String name;

    @Column
    private String gender;

    @Column(name = "person_constellation")
    private Integer constellation;

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @Column(name = "person_birth_date")
    private Date birthDate;

    @Column(name = "person_profession")
    private String profession;

    @Column(name = "person_other_name")
    private String otherName;

    @OneToOne(fetch = FetchType.LAZY, cascade = {CascadeType.REFRESH, CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST})
    private Place birthPlace;

    @Column(name = "person_description")
    private String description;

    @Column(name = "person_image")
    private String image;

    @OneToOne(cascade = CascadeType.ALL)
    private Actor actor;

    @OneToOne(cascade = CascadeType.ALL)
    private Director directors;

    @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")
    private Date updateDate;

    @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", updatable = false)
    private Date createDate;

    public Person() {
    }

    public Person(String name) {
        this.name = name;
    }

    public Person(String name, String gender, Integer constellation, Date birthDate, String profession, String otherName, Place birthPlace, String description) {

        this.name = name;
        this.gender = gender;
        this.constellation = constellation;
        this.birthDate = birthDate;
        this.profession = profession;
        this.otherName = otherName;
        this.birthPlace = birthPlace;
        this.description = description;
    }
}